// pages/garbage/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startX: '',
    startY: '',
    curIndex: 0,
    card_list: ['a', 'b', 'c'],
    lastIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUnit()
  },
  getUnit() {
    let that = this
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          unit: res.screenWidth / 100
        })
      },
    })
  },
  touchStart(e) {
    let that = this
    this.startX = e.touches[0].clientX - 28.125
    this.startY = e.touches[0].clientY - 28.125
    console.log(e)
    that.setData({
      positionX: this.startX,
      positionY: this.startY,
      currentX: e.currentTarget.offsetLeft,
      currentY: e.currentTarget.offsetTop
    })
  },
  touchMove(e) {
    let that = this
    this.moveX = e.touches[0].clientX
    this.moveY = e.touches[0].clientY
    console.log(e)
    that.setData({
      positionX: e.touches[0].clientX - 28.125,
      positionY: e.touches[0].clientY - 28.125
    })
  },
  touchEnd(e) {
    let that = this
    console.log(that.data.currentX, that.data.currentY)
    console.log(this.moveX, this.moveY)
    let curIndex = that.data.curIndex
    if ((this.moveX > 4 * that.data.unit && this.moveX < 24 * that.data.unit) && (this.moveY > 50 * that.data.unit && this.moveY < 70 * that.data.unit)) {
      curIndex++
    }
    that.setData({
      positionX: that.data.currentX,
      positionY: that.data.currentY,
      curIndex
    })
  },
  touchCancel(e) {
    let that = this
    that.setData({
      positionX: '',
      positionY: ''
    })
  },
  // 加载新数据
  toggleTime(e) {
    let that = this
    console.log(e, that.data.lastIndex)
    if (e.detail.current == that.data.card_list.length - 1) {
      that.data.card_list.push(that.data.card_list.length)
      console.log(that.data.card_list)
      that.setData({
        card_list: that.data.card_list
      })
    } else if (that.data.lastIndex == e.detail.current) {
      that.data.card_list.unshift(that.data.card_list.length)
      console.log(that.data.card_list)
      that.setData({
        card_list: that.data.card_list
      })
    }
    that.setData({
      lastIndex: e.detail.current
    })
    // let arr = this.card_list.push(4)
    // that.setData({
    //   card_list: arr
    // })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})